﻿namespace WMS6.Web.Analytics
{
    using System;
    using System.Data;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using WMS6.Web;
    using WMS6.Web.AnalyticsReportServiceRef;
    using WMS6.Web.UserControls;

    public class FinanceInOutStockDetailRptList : BasePage
    {
        protected Button btnExport;
        protected Button btnList;
        protected Button btnRefresh;
        protected Button btnReSearch;
        protected Button btnSearch;
        private decimal CurrentIssueInboundPrice;
        private decimal CurrentIssueInboundQty;
        protected HtmlForm F15311;
        protected GridView gvFinanceInOutStockDetailRptList;
        protected GridView gvFinanceInOutStockDetailRptListShowLot;
        protected HtmlInputHidden hdnActionID;
        protected HtmlInputHidden hdnFrom;
        protected HtmlInputHidden hdnShowLot;
        protected HtmlHead Head1;
        protected Label lblFinanceInOutStockDetailRptList;
        protected Label lblMsg;
        protected Label lblTotalAdjustQty;
        protected Label lblTotalAdjustQtyText;
        protected Label lblTotalAjustAmount;
        protected Label lblTotalAjustAmountText;
        protected Label lblTotalBeginningExtendedPrice;
        protected Label lblTotalBeginningExtendedPriceText;
        protected Label lblTotalBeginningPrice;
        protected Label lblTotalBeginningPriceText;
        protected Label lblTotalBeginningQty;
        protected Label lblTotalBeginningQtyText;
        protected Label lblTotalCurrentIssueInboundPrice;
        protected Label lblTotalCurrentIssueInboundPriceText;
        protected Label lblTotalCurrentIssueInboundQty;
        protected Label lblTotalCurrentIssueInboundQtyText;
        protected Label lblTotalCurrentIssueOutBoundPrice;
        protected Label lblTotalCurrentIssueOutBoundPriceText;
        protected Label lblTotalCurrentIssueOutBoundQty;
        protected Label lblTotalCurrentIssueOutBoundQtyText;
        protected Label lblTotalEndExtendedPrice;
        protected Label lblTotalEndExtendedPriceText;
        protected Label lblTotalEndPrice;
        protected Label lblTotalEndPriceText;
        protected Label lblTotalEndQty;
        protected Label lblTotalEndQtyText;
        protected HtmlLink mycss;
        protected Pager PagerFooter;
        protected ScriptManager ScriptManager1;
        private decimal TotalAdjustAmount;
        private decimal TotalAdjustQty;
        private decimal TotalBeginningExtendedPrice;
        private decimal TotalBeginningPrice;
        private decimal TotalBeginningQty;
        private decimal TotalCurrentIssueOutBoundPrice;
        private decimal TotalCurrentIssueOutBoundQty;
        private decimal TotalEndExtendedPrice;
        private decimal TotalEndPrice;
        private decimal TotalEndQty;
        protected UpdatePanel up1;

        public void BindData2FinanceInOutStockDetailRpt(FinanceInOutStockDetailRptQueryEntity financeInOutStockDetailRptQueryEntity)
        {
            this.PagerFooter.CurrentPage = int.Parse(financeInOutStockDetailRptQueryEntity.CurrentPage);
            DataSet ds = AnalyticsReportServiceClientProxy.GetInstance().GetFinanceInOutStockDetailRptDataSet(financeInOutStockDetailRptQueryEntity);
            if (financeInOutStockDetailRptQueryEntity.ShowLot == "Y")
            {
                base.BindData2GridView(this.gvFinanceInOutStockDetailRptListShowLot, ds);
            }
            else
            {
                base.BindData2GridView(this.gvFinanceInOutStockDetailRptList, ds);
            }
            if ((ds != null) && (ds.Tables.Count > 1))
            {
                this.PagerFooter.PageInfo = ds.Tables[1].Rows[0]["CurrentPage"].ToString() + " / " + ds.Tables[1].Rows[0]["TotalPagesCount"].ToString() + "&nbsp;&nbsp;&nbsp;共: " + ds.Tables[1].Rows[0]["TotalRecordsCount"].ToString();
                this.PagerFooter.TotalPages = int.Parse(ds.Tables[1].Rows[0]["TotalPagesCount"].ToString());
            }
        }

        protected void btnExport_Click(object sender, EventArgs e)
        {
            FinanceInOutStockDetailRptQueryEntity financeInOutStockDetailRptQueryEntity = this.GetFinanceInOutStockDetailRptQueryEntity();
            financeInOutStockDetailRptQueryEntity.IsGetAll = true;
            this.hdnActionID.Value = "EXPORT";
            string currentPageIndex = financeInOutStockDetailRptQueryEntity.CurrentPage;
            financeInOutStockDetailRptQueryEntity.CurrentPage = "0";
            try
            {
                using (DataSet ds = AnalyticsReportServiceClientProxy.GetInstance().GetFinanceInOutStockDetailRptDataSet(financeInOutStockDetailRptQueryEntity))
                {
                    if (financeInOutStockDetailRptQueryEntity.ShowLot == "Y")
                    {
                        base.Export2Excel("FinanceInOutStockDetailRpt.xls", "15311", this.gvFinanceInOutStockDetailRptListShowLot, ds);
                    }
                    else
                    {
                        base.Export2Excel("FinanceInOutStockDetailRpt.xls", "15311", this.gvFinanceInOutStockDetailRptList, ds);
                    }
                }
            }
            finally
            {
                financeInOutStockDetailRptQueryEntity.IsGetAll = false;
                financeInOutStockDetailRptQueryEntity.CurrentPage = currentPageIndex;
                this.SetFinanceInOutStockDetailRptQueryEntity(financeInOutStockDetailRptQueryEntity);
            }
        }

        protected void btnFirst_Click(object sender, EventArgs e)
        {
            FinanceInOutStockDetailRptQueryEntity financeInOutStockDetailRptQueryEntity = this.GetFinanceInOutStockDetailRptQueryEntity();
            financeInOutStockDetailRptQueryEntity.CurrentPage = "0";
            this.BindData2FinanceInOutStockDetailRpt(financeInOutStockDetailRptQueryEntity);
        }

        protected void btnLast_Click(object sender, EventArgs e)
        {
            FinanceInOutStockDetailRptQueryEntity financeInOutStockDetailRptQueryEntity = this.GetFinanceInOutStockDetailRptQueryEntity();
            financeInOutStockDetailRptQueryEntity.CurrentPage = (this.PagerFooter.TotalPages - 1).ToString();
            this.BindData2FinanceInOutStockDetailRpt(financeInOutStockDetailRptQueryEntity);
        }

        protected void btnList_Click(object sender, EventArgs e)
        {
            FinanceInOutStockDetailRptQueryEntity financeInOutStockDetailRptQueryEntity = this.GetFinanceInOutStockDetailRptQueryEntity();
            financeInOutStockDetailRptQueryEntity.OwnerID = "";
            financeInOutStockDetailRptQueryEntity.SkuID = "";
            financeInOutStockDetailRptQueryEntity.StartTime = "";
            financeInOutStockDetailRptQueryEntity.EndTime = "";
            this.BindData2FinanceInOutStockDetailRpt(financeInOutStockDetailRptQueryEntity);
        }

        protected void btnNext_Click(object sender, EventArgs e)
        {
            FinanceInOutStockDetailRptQueryEntity financeInOutStockDetailRptQueryEntity = this.GetFinanceInOutStockDetailRptQueryEntity();
            if (int.Parse(financeInOutStockDetailRptQueryEntity.CurrentPage) < (this.PagerFooter.TotalPages - 1))
            {
                financeInOutStockDetailRptQueryEntity.CurrentPage = (int.Parse(financeInOutStockDetailRptQueryEntity.CurrentPage) + 1).ToString();
                this.BindData2FinanceInOutStockDetailRpt(financeInOutStockDetailRptQueryEntity);
            }
        }

        protected void btnPrevious_Click(object sender, EventArgs e)
        {
            FinanceInOutStockDetailRptQueryEntity financeInOutStockDetailRptQueryEntity = this.GetFinanceInOutStockDetailRptQueryEntity();
            if (int.Parse(financeInOutStockDetailRptQueryEntity.CurrentPage) > 0)
            {
                financeInOutStockDetailRptQueryEntity.CurrentPage = (int.Parse(financeInOutStockDetailRptQueryEntity.CurrentPage) - 1).ToString();
                this.BindData2FinanceInOutStockDetailRpt(financeInOutStockDetailRptQueryEntity);
            }
        }

        protected void btnRefresh_Click(object sender, EventArgs e)
        {
            FinanceInOutStockDetailRptQueryEntity financeInOutStockDetailRptQueryEntity = this.GetFinanceInOutStockDetailRptQueryEntity();
            this.BindData2FinanceInOutStockDetailRpt(financeInOutStockDetailRptQueryEntity);
        }

        private FinanceInOutStockDetailRptQueryEntity GetFinanceInOutStockDetailRptQueryEntity()
        {
            return (base.PageQueryEntitySession as FinanceInOutStockDetailRptQueryEntity);
        }

        protected void GoTo_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(((TextBox) this.PagerFooter.FindControl("txtGo2Page")).Text.Trim()))
            {
                FinanceInOutStockDetailRptQueryEntity financeInOutStockDetailRptQueryEntity = this.GetFinanceInOutStockDetailRptQueryEntity();
                financeInOutStockDetailRptQueryEntity.CurrentPage = this.PagerFooter.GoToPage.ToString();
                this.BindData2FinanceInOutStockDetailRpt(financeInOutStockDetailRptQueryEntity);
            }
        }

        protected void gvFinanceInOutStockDetailRptList_Init(object sender, EventArgs e)
        {
            base.InitDetailGridView("15311", this.gvFinanceInOutStockDetailRptList);
        }

        protected void gvFinanceInOutStockDetailRptList_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Cells[0].Text = (((this.PagerFooter.CurrentPage * this.PagerFooter.PageSize) + e.Row.RowIndex) + 1).ToString();
                e.Row.Attributes.Add("onmouseout", "GridViewRowMouseout(this);");
                e.Row.Attributes.Add("onmouseover", "GridViewRowMouseover(this);");
                ((CheckBox) e.Row.FindControl("chbSelect")).Attributes.Add("onclick", "GridViewCheckBoxClick('" + e.Row.ClientID + "')");
                e.Row.Attributes.Add("ondblclick", "JavaScript:document.getElementById('" + ((CheckBox) e.Row.FindControl("chbSelect")).ClientID + "').click();");
                if (this.hdnActionID.Value != "EXPORT")
                {
                    base.SetGridViewLongTextLabel((Label) e.Row.FindControl("lblDESCR"));
                }
                if (((Label) e.Row.FindControl("lblBeginningQty")) != null)
                {
                    this.TotalBeginningQty += decimal.Parse((((Label) e.Row.FindControl("lblBeginningQty")).Text != "") ? ((Label) e.Row.FindControl("lblBeginningQty")).Text : "0");
                }
                if (((Label) e.Row.FindControl("lblBeginningPrice")) != null)
                {
                    this.TotalBeginningPrice += decimal.Parse((((Label) e.Row.FindControl("lblBeginningPrice")).Text != "") ? ((Label) e.Row.FindControl("lblBeginningPrice")).Text : "0");
                }
                if (((Label) e.Row.FindControl("lblBeginningExtendedPrice")) != null)
                {
                    this.TotalBeginningExtendedPrice += decimal.Parse((((Label) e.Row.FindControl("lblBeginningExtendedPrice")).Text != "") ? ((Label) e.Row.FindControl("lblBeginningExtendedPrice")).Text : "0");
                }
                if (((Label) e.Row.FindControl("lblCurrentIssueInboundQty")) != null)
                {
                    this.CurrentIssueInboundQty += decimal.Parse((((Label) e.Row.FindControl("lblCurrentIssueInboundQty")).Text != "") ? ((Label) e.Row.FindControl("lblCurrentIssueInboundQty")).Text : "0");
                }
                if (((Label) e.Row.FindControl("lblCurrentIssueInboundPrice")) != null)
                {
                    this.CurrentIssueInboundPrice += decimal.Parse((((Label) e.Row.FindControl("lblCurrentIssueInboundPrice")).Text != "") ? ((Label) e.Row.FindControl("lblCurrentIssueInboundPrice")).Text : "0");
                }
                if (((Label) e.Row.FindControl("lblCurrentIssueOutBoundQty")) != null)
                {
                    this.TotalCurrentIssueOutBoundQty += decimal.Parse((((Label) e.Row.FindControl("lblCurrentIssueOutBoundQty")).Text != "") ? ((Label) e.Row.FindControl("lblCurrentIssueOutBoundQty")).Text : "0");
                }
                if (((Label) e.Row.FindControl("lblCurrentIssueOutBoundPrice")) != null)
                {
                    this.TotalCurrentIssueOutBoundPrice += decimal.Parse((((Label) e.Row.FindControl("lblCurrentIssueOutBoundPrice")).Text != "") ? ((Label) e.Row.FindControl("lblCurrentIssueOutBoundPrice")).Text : "0");
                }
                if (((Label) e.Row.FindControl("lblAjustQty")) != null)
                {
                    this.TotalAdjustQty += decimal.Parse((((Label) e.Row.FindControl("lblAjustQty")).Text != "") ? ((Label) e.Row.FindControl("lblAjustQty")).Text : "0");
                }
                if (((Label) e.Row.FindControl("lblAdjustAmount")) != null)
                {
                    this.TotalAdjustAmount += decimal.Parse((((Label) e.Row.FindControl("lblAdjustAmount")).Text != "") ? ((Label) e.Row.FindControl("lblAdjustAmount")).Text : "0");
                }
                if (((Label) e.Row.FindControl("lblEndQty")) != null)
                {
                    this.TotalEndQty += decimal.Parse((((Label) e.Row.FindControl("lblEndQty")).Text != "") ? ((Label) e.Row.FindControl("lblEndQty")).Text : "0");
                }
                if (((Label) e.Row.FindControl("lblEndPrice")) != null)
                {
                    this.TotalEndPrice += decimal.Parse((((Label) e.Row.FindControl("lblEndPrice")).Text != "") ? ((Label) e.Row.FindControl("lblEndPrice")).Text : "0");
                }
                if (((Label) e.Row.FindControl("lblEndExtendedPrice")) != null)
                {
                    this.TotalEndExtendedPrice += decimal.Parse((((Label) e.Row.FindControl("lblEndExtendedPrice")).Text != "") ? ((Label) e.Row.FindControl("lblEndExtendedPrice")).Text : "0");
                }
            }
            if (e.Row.RowType == DataControlRowType.Footer)
            {
                this.lblTotalBeginningQtyText.Text = base.GetPreferenceDigit(this.TotalBeginningQty);
                this.lblTotalBeginningPriceText.Text = base.GetPreferenceDigit(this.TotalBeginningPrice);
                this.lblTotalBeginningExtendedPriceText.Text = base.GetPreferenceDigit(this.TotalBeginningExtendedPrice);
                this.lblTotalCurrentIssueInboundQtyText.Text = base.GetPreferenceDigit(this.CurrentIssueInboundQty);
                this.lblTotalCurrentIssueInboundPriceText.Text = base.GetPreferenceDigit(this.CurrentIssueInboundPrice);
                this.lblTotalCurrentIssueOutBoundQtyText.Text = base.GetPreferenceDigit(this.TotalCurrentIssueOutBoundQty);
                this.lblTotalCurrentIssueOutBoundPriceText.Text = base.GetPreferenceDigit(this.TotalCurrentIssueOutBoundPrice);
                this.lblTotalAdjustQtyText.Text = base.GetPreferenceDigit(this.TotalAdjustQty);
                this.lblTotalAjustAmountText.Text = base.GetPreferenceDigit(this.TotalAdjustAmount);
                this.lblTotalEndQtyText.Text = base.GetPreferenceDigit(this.TotalEndQty);
                this.lblTotalEndPriceText.Text = base.GetPreferenceDigit(this.TotalEndPrice);
                this.lblTotalEndExtendedPriceText.Text = base.GetPreferenceDigit(this.TotalEndExtendedPrice);
            }
        }

        protected void gvFinanceInOutStockDetailRptList_Sorting(object sender, GridViewSortEventArgs e)
        {
            try
            {
                FinanceInOutStockDetailRptQueryEntity financeInOutStockDetailRptQueryEntity = this.GetFinanceInOutStockDetailRptQueryEntity();
                financeInOutStockDetailRptQueryEntity.SortField = e.SortExpression;
                if ((financeInOutStockDetailRptQueryEntity.SortDirection == "ASC") || (financeInOutStockDetailRptQueryEntity.SortDirection.Trim() == ""))
                {
                    financeInOutStockDetailRptQueryEntity.SortDirection = "DESC";
                }
                else if (financeInOutStockDetailRptQueryEntity.SortDirection == "DESC")
                {
                    financeInOutStockDetailRptQueryEntity.SortDirection = "ASC";
                }
                this.BindData2FinanceInOutStockDetailRpt(financeInOutStockDetailRptQueryEntity);
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
            }
        }

        protected void gvFinanceInOutStockDetailRptListShowLot_Init(object sender, EventArgs e)
        {
            base.InitDetailGridView("15311", this.gvFinanceInOutStockDetailRptListShowLot);
        }

        private void LoadData()
        {
            FinanceInOutStockDetailRptQueryEntity financeInOutStockDetailRptQueryEntity = new FinanceInOutStockDetailRptQueryEntity();
            if (string.IsNullOrEmpty(base.Request.QueryString["from"]))
            {
                if (this.PreviousPage != null)
                {
                    financeInOutStockDetailRptQueryEntity.OwnerID = this.PreviousPage.OwnerID;
                    financeInOutStockDetailRptQueryEntity.SkuID = this.PreviousPage.SkuID;
                    financeInOutStockDetailRptQueryEntity.SkuClassID = this.PreviousPage.SkuClassID;
                    financeInOutStockDetailRptQueryEntity.VendorID = this.PreviousPage.VendorID;
                    financeInOutStockDetailRptQueryEntity.StartTime = this.PreviousPage.StartTime;
                    financeInOutStockDetailRptQueryEntity.EndTime = this.PreviousPage.EndTime;
                    financeInOutStockDetailRptQueryEntity.ShowLot = this.PreviousPage.ShoLot;
                    financeInOutStockDetailRptQueryEntity.LOT_ATTR01 = this.PreviousPage.LotAttribute01;
                    financeInOutStockDetailRptQueryEntity.LOT_ATTR02 = this.PreviousPage.LotAttribute02;
                    financeInOutStockDetailRptQueryEntity.LOT_ATTR03 = this.PreviousPage.LotAttribute03;
                    financeInOutStockDetailRptQueryEntity.LOT_ATTR04 = this.PreviousPage.LotAttribute04;
                    financeInOutStockDetailRptQueryEntity.LOT_ATTR05 = this.PreviousPage.LotAttribute05;
                    financeInOutStockDetailRptQueryEntity.LOT_ATTR06 = this.PreviousPage.LotAttribute06;
                    financeInOutStockDetailRptQueryEntity.LOT_ATTR07 = this.PreviousPage.LotAttribute07;
                    financeInOutStockDetailRptQueryEntity.LOT_ATTR08 = this.PreviousPage.LotAttribute08;
                    financeInOutStockDetailRptQueryEntity.LOT_ATTR09 = this.PreviousPage.LotAttribute09;
                    financeInOutStockDetailRptQueryEntity.LOT_ATTR10 = this.PreviousPage.LotAttribute10;
                    financeInOutStockDetailRptQueryEntity.EXPIRY_DATE = this.PreviousPage.ExpiryDate;
                    financeInOutStockDetailRptQueryEntity.PRODUCE_DATE = this.PreviousPage.ProduceDate;
                    financeInOutStockDetailRptQueryEntity.EXTERNAL_LOT = this.PreviousPage.ExternalLot;
                }
                else
                {
                    financeInOutStockDetailRptQueryEntity.OwnerID = "";
                    financeInOutStockDetailRptQueryEntity.SkuID = "";
                    financeInOutStockDetailRptQueryEntity.StartTime = "";
                    financeInOutStockDetailRptQueryEntity.EndTime = "";
                    financeInOutStockDetailRptQueryEntity.ShowLot = "N";
                }
                if (financeInOutStockDetailRptQueryEntity.ShowLot == "Y")
                {
                    this.gvFinanceInOutStockDetailRptListShowLot.Visible = true;
                    this.gvFinanceInOutStockDetailRptList.Visible = false;
                }
            }
            else
            {
                this.hdnFrom.Value = base.Request.QueryString["from"].ToString();
            }
            financeInOutStockDetailRptQueryEntity.IsGetAll = false;
            financeInOutStockDetailRptQueryEntity.CurrentPage = "0";
            financeInOutStockDetailRptQueryEntity.SortField = "IL.OWNER_ID, IL.SKU_ID";
            financeInOutStockDetailRptQueryEntity.SortDirection = "";
            if (financeInOutStockDetailRptQueryEntity.ShowLot == "Y")
            {
                financeInOutStockDetailRptQueryEntity.PageSize = this.gvFinanceInOutStockDetailRptListShowLot.PageSize.ToString();
                this.PagerFooter.PageSize = this.gvFinanceInOutStockDetailRptListShowLot.PageSize;
            }
            else
            {
                financeInOutStockDetailRptQueryEntity.PageSize = this.gvFinanceInOutStockDetailRptList.PageSize.ToString();
                this.PagerFooter.PageSize = this.gvFinanceInOutStockDetailRptList.PageSize;
            }
            this.SetFinanceInOutStockDetailRptQueryEntity(financeInOutStockDetailRptQueryEntity);
            this.BindData2FinanceInOutStockDetailRpt(financeInOutStockDetailRptQueryEntity);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                base.InitPage(this.Page);
                base.InitAnalyticsReportGridview(this.gvFinanceInOutStockDetailRptList);
                this.LoadData();
            }
        }

        public void SetFinanceInOutStockDetailRptQueryEntity(FinanceInOutStockDetailRptQueryEntity financeInOutStockDetailRptQueryEntity)
        {
            base.PageQueryEntitySession = financeInOutStockDetailRptQueryEntity;
        }

        public FinanceInOutStockDetailRptQuery PreviousPage
        {
            get
            {
                return (FinanceInOutStockDetailRptQuery) base.PreviousPage;
            }
        }
    }
}

